package com.define.commons.query.core;

import com.define.commons.query.contract.PageContract;
import lombok.Data;

/**
 * 自定义查询包装类
 * 支持连缀的方式设置参数
 * @Author xiewenlong
 * @Date 2018/10/31 12:49
 */
@Data
public class Query {

    private Integer page = PageContract.DEFAULT_PAGE_NUMBER;
    private Integer pageSize = PageContract.DEFAULT_PAGE_SIZE;
    private String sorts;
    private Object params;

    public Query() {
    }

    public Query(Object params) {
        this.params = params;
    }

    public Query(String sorts) {
        this.sorts = sorts;
    }

    public Query(Integer page, Integer pageSize) {
        this.page = page;
        this.pageSize = pageSize;
    }

    public Query(String page, String pageSize) {
        this.page = Integer.valueOf(page);
        this.pageSize = Integer.valueOf(pageSize);
    }

    public Query(Object params, String page, String pageSize) {
        this(page, pageSize);
        this.params = params;
    }

    public Query(Object params, Integer page, Integer pageSize) {
        this(page, pageSize);
        this.params = params;
    }

    public Query(String sorts, Object params, String page, String pageSize) {
        this(params, page, pageSize);
        this.sorts = sorts;
    }

    public Query(String sorts, Object params, Integer page, Integer pageSize) {
        this(params, page, pageSize);
        this.sorts = sorts;
    }

    //连缀
    public Query page(Integer page) {
        this.page = page;
        return this;
    }

    public Query pageSize(Integer pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public Query sorts(String sorts) {
        this.sorts = sorts;
        return this;
    }

    public Query params(Object params) {
        this.params = params;
        return this;
    }
}
